package com.viphuli.app.tool.fragment;

import net.simonvt.numberpicker.NumberPicker;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.OnClick;

import com.viphuli.app.tool.R;

public class NumberPickerDialogFragment extends BaseProgressBottomDialogFragment {

	@Bind(R.id.number_picker)
	protected NumberPicker numberPicker;

	@Bind(R.id.number_picker_unit)
	protected TextView numberPickerUnit;
	
	private NumberClickListener clickListener;

	private int min;
	private int max;
	private String unit;

	public NumberPickerDialogFragment(NumberClickListener clickListener, int min, int max, String unit) {
		this.clickListener = clickListener;

		this.min = min;
		this.max = max;
		this.unit = unit;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		//无标题
		getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);

		return super.onCreateView(inflater, container, savedInstanceState);
	}

	@Override
	protected int obtainContentRes() {
		return R.layout.dialog_number_picker;
	}

	@Override
	protected void initParams() {

	}

	@Override
	protected void initView() {

		numberPicker.setMaxValue(max);
		numberPicker.setMinValue(min);
		numberPicker.setValue(min);
		numberPicker.setFocusable(true);
		numberPicker.setFocusableInTouchMode(true);
		
		numberPickerUnit.setText(unit);

	}

	@Override
	protected void initData() {

	}

	@OnClick(R.id.id_btn_cacel)
	public void clickCancel() {

		dismiss();

	}

	@OnClick(R.id.id_btn_enter)
	public void clickEnter() {

		dismiss();

		int number = numberPicker.getValue();

		if (clickListener != null)
			clickListener.onEnsure(number);
	}

	public interface NumberClickListener {
		void onEnsure(int number);
	}

}
